﻿package client;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import server.ComPropertyInterface;
import server.PersonInterface;

import client.Configuration;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;


public class ComPropertyGUI extends JDialog {

	private JPanel contentPane;
	Person p = new Person();
	int pid=p.getPID();

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ComPropertyGUI frame = new ComPropertyGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	/**
	 * Create the frame.
	 */
	public ComPropertyGUI() {
		setTitle("Property Load");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnNewButton = new JButton("\u6253\u626B");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
                  try {
					
					Configuration config = new Configuration();
					String rmiAddress=config.getRmiAddress();
					ComPropertyInterface comProperty = (ComPropertyInterface) Naming.lookup(rmiAddress+"ComProperty"); 
					double m = comProperty.getMon();
					System.out.print(m);
					
					PersonInterface person = (PersonInterface) Naming.lookup(rmiAddress+"Person");
					boolean z = person.cashChanges(pid, m, '-');
					if(z)
					    JOptionPane.showMessageDialog(null, "打扫干净");
					else
						JOptionPane.showMessageDialog(null, "您没有交钱");
			      } catch (MalformedURLException e1) {
				        // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (RemoteException e1) {
				         // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (NotBoundException e1) {
				          // TODO Auto-generated catch block
				        e1.printStackTrace();
			      }
			}
		});
		btnNewButton.setBounds(269, 22, 122, 44);
		contentPane.add(btnNewButton);
		
		JButton button = new JButton("\u4FDD\u5B89");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
                 try {
					
					Configuration config = new Configuration();
					String rmiAddress=config.getRmiAddress();
					ComPropertyInterface comProperty = (ComPropertyInterface) Naming.lookup(rmiAddress+"ComProperty"); 
					double m = comProperty.getMon();
					System.out.print(m);
					
			
			
					JOptionPane.showMessageDialog(null, "小区治安良好");
			      } catch (MalformedURLException e1) {
				        // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (RemoteException e1) {
				         // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (NotBoundException e1) {
				          // TODO Auto-generated catch block
				        e1.printStackTrace();
			} 
			}
		});
		button.setBounds(269, 97, 122, 44);
		contentPane.add(button);
		
		JButton button_1 = new JButton("\u4FEE\u7406");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
                try {
					
					Configuration config = new Configuration();
					String rmiAddress=config.getRmiAddress();
					ComPropertyInterface comProperty = (ComPropertyInterface) Naming.lookup(rmiAddress+"ComProperty"); 
					double m = comProperty.getMon();
					System.out.print(m);
					
					PersonInterface person = (PersonInterface) Naming.lookup(rmiAddress+"Person");
					boolean z = person.cashChanges(pid, m, '-');
					if(z)
					    JOptionPane.showMessageDialog(null, "修理成功");
					else
						JOptionPane.showMessageDialog(null, "您没有交钱");
			      } catch (MalformedURLException e1) {
				        // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (RemoteException e1) {
				         // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } catch (NotBoundException e1) {
				          // TODO Auto-generated catch block
				        e1.printStackTrace();
			      } 
			}
		});
		button_1.setBounds(269, 170, 122, 44);
		contentPane.add(button_1);
		
		JLabel lblNewLabel = new JLabel("\u4EB2~\u6B22\u8FCE\u6765\u5230\u7269\u4E1A\u533A\r\n\u8BF7\u9009\u62E9\u60A8\u6240\u8981\u7684\u670D\u52A1\uFF01");
		lblNewLabel.setBounds(10, 22, 249, 111);
		contentPane.add(lblNewLabel);
		
		JButton button_2 = new JButton("\u8FD4\u56DE");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				ComLoadGUI clg = new ComLoadGUI();
				clg.setLocationRelativeTo(null);
				clg.setVisible(true);
			}
		});
		button_2.setBounds(39, 197, 79, 30);
		contentPane.add(button_2);
	}
}
